//
//  HeaderCollectionReusableView.m
//  Homework_14
//
//  Created by 徐昊 on 16/8/2.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "HeaderCollectionReusableView.h"
#import "CustomCollectionViewCell.h"
#define kCollectionReuse @"reuseNO"
@interface HeaderCollectionReusableView ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UITextField *textField;
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UIButton *button;
@end

@implementation HeaderCollectionReusableView
- (instancetype)initWithFrame:(CGRect)frame {
    self  = [super initWithFrame:frame];
    if (self) {
        _textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, CGRectGetWidth(self.bounds) - 10, 40)];
        _textField.placeholder = @"快选一份七夕礼物, 送给心爱的Ta吧";
        _textField.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_textField];
        _label = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, 60, 40)];
        _label.text = @"栏目";
        [self addSubview:_label];
        _button = [UIButton buttonWithType:UIButtonTypeSystem];
        _button.frame = CGRectMake(CGRectGetWidth(self.bounds) - 80, 60, 80, 40);
        [_button setTitle:@"查看全部" forState:UIControlStateNormal];
        [self addSubview:_button];
        // 创建collectionView
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 110, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) - 110) collectionViewLayout:layout];
        layout.itemSize = CGSizeMake(CGRectGetWidth(self.bounds) - 50, (CGRectGetHeight(self.bounds) - 150) / 3);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor whiteColor];
        [_collectionView registerClass:[CustomCollectionViewCell class] forCellWithReuseIdentifier:kCollectionReuse];
        [self addSubview:_collectionView];
    }
    return self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 10;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollectionReuse forIndexPath:indexPath];
    cell.backgroundColor = [UIColor greenColor];
    return cell;
}
@end
